home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86v307c.arc / 13TOOLS.DOC < prev    next >
Text File  |  1987-07-13  |  16KB  |  332 lines

  1. CHAPTER 13   ASSOCIATED TOOLS                             13-1
  2.  
  3.  
  4. XREF Cross-reference and Symbol Listing Facility
  5.  
  6.  
  7. XREF is a tool that creates a cross-referenced symbol table 
  8. listing of your program.  
  9.  
  10. To invoke XREF, you must provide a program invocation line, 
  11. either typed to the console when the DOS command prompt appears, 
  12. or included in a batch file.  The program invocation line 
  13. consists of the following: 
  14.  
  15. 1. The program name XREF.
  16.  
  17. 2. The name of a symbol-table file produced by A86 when you 
  18.    assembled your program.  If you do not give an extension, XREF 
  19.    assumes a .SYM extension; if you wish no extension, you give a 
  20.    period without an extension.  Note that if you follow normal 
  21.    methodology, the name of the symbol-table file is the same as 
  22.    the name of the program.  
  23.  
  24. 3. The same list of source-file names that you gave to A86.  Just 
  25.    as with A86, you may use the wild-card delimiters * and ? if 
  26.    you wish, with the same results.  
  27.  
  28.    XREF, like A86, identifies the end of the source file names 
  29.    when it sees a name with no extension, or a name with the 
  30.    default output-extension.  For XREF, that extension is .XRF.  
  31.  
  32. 3. You may optionally provide the word TO, to separate the source 
  33.    file names from the output file names.  
  34.  
  35. 4. The name of the output listing file.  If you do not provide an 
  36.    extension, XREF will assume that you want the extension .XRF. 
  37.    If you want your program file to have no extension, you end 
  38.    the file name with a period.  
  39.  
  40.    You have the option to omit the output file name.  If you do, 
  41.    XREF will use the name of the symbol-table file, with the 
  42.    extension .XRF.  
  43.  
  44.  
  45. The output of XREF is an alphabetical listing of all the non-
  46. local symbols in your program.  For each symbol, XREF gives its 
  47. type, the file in which it was defined, its value, and a list of 
  48. all procedures in which the file was used.  If you print this 
  49. file, you typically use the TCOLS tool to obtain a multi-column 
  50. listing from XREF's single-column output.  
  51.  
  52. Note the use of procedure names to identify references -- this is 
  53. unique to the A86 package, and makes the cross-reference listing 
  54. truly readable.  Other cross-reference listings give either line 
  55. numbers, which are meaningless unless you go find the associated 
  56. line; or a file-name, which doesn't give you as much useful 
  57. information.  
  58.                                                           13-2
  59. Here is a more detailed description of the various pieces of 
  60. information provided for each symbol: 
  61.  
  62. 1. TYPE.  Labels are indicated by a colon immediately following 
  63.    the symbol-name.  Special symbols such as macro names are 
  64.    denoted by an appropriate word such as "macro" in place of the 
  65.    value on the following line.  Other symbols types are 
  66.    described by one or two characters, following the symbol name.  
  67.    Possibilities for the first character are: 
  68.  
  69.         m  for a simple memory variable
  70.         +  for an index memory quantity
  71.         c  for a constant
  72.         i  for an interrupt-equate
  73.         s  for a structure
  74.  
  75.     If there is a second letter, it is a size attribute: b for 
  76.     byte, w for word, f for far (or doubleword).  
  77.  
  78. 2. FILE in which the symbol was defined.  The name is stripped of 
  79.    its extension, which is presumably the same for all your 
  80.    source files.  The name is preceded by = or period , which 
  81.    denotes a definition, not a reference, of the symbol.  
  82.  
  83. 3. VALUE, given as 4 hex digits, on the line following the 
  84.    symbol.  For memory variables, this is the location of the 
  85.    variable.  For indexed quantities, this is the constant-
  86.    displacement part of the quantity.  For structures, it is the 
  87.    size of the structure.  For interrupt-equates, it is the 
  88.    number of the interrupt.  
  89.  
  90. 4. REFERENCES, given on indented lines following the symbol name. 
  91.    All occurrences of the symbol in your program produce a 
  92.    reference.  If the symbol is the first thing of a line, it is 
  93.    considered a "definition" of that symbol, the reference listed 
  94.    is the source file name.  The name is preceded by a period if 
  95.    the definition was via a colon (i.e., a label); it is preceded 
  96.    by an equals-sign otherwise. If the symbol is not the first 
  97.    thing of the line, then it is not a definition.  The 
  98.    reference-listing consists of the name of the last definition 
  99.    that XREF scanned (which, if your program is organized in a 
  100.    standard way, will be the name of the procedure in which the 
  101.    reference occurred.  
  102.  
  103.    Observe that you must use the local-label facility of A86 to 
  104.    make this work.  If you don't use local-labels as your "place-
  105.    marker" symbols, the symbol XREF gives you will often be the 
  106.    name of the last "place-marker" symbol, not the name of the 
  107.    last procedure.  
  108.  
  109.    To save space, duplicate reference-entries are denoted by a 
  110.    single entry, followed by "*n", where n is the decimal number 
  111.    of occurrences of that entry.  
  112.                                                           13-3
  113. EXMAC Macro Expansion Tool
  114.  
  115. There is a tool called EXMAC which will help you troubleshoot A86 
  116. program lines that call macros.  If you are not sure about what 
  117. code is being generated by your macro calls, EXMAC will tell you.  
  118.  
  119. To use this tool, you must first assemble your macro definitions, 
  120. to produce a symbol-table file.  If your entire program assembled 
  121. without errors, then you will already have this symbols-file; it 
  122. is usually called myprog.SYM, where "myprog" is the name of your 
  123. .COM file.  If your program did not assemble correctly, the 
  124. symbol-table file will be named "fname.SYM", where fname is the 
  125. name of the source file that contained errors.  
  126.  
  127. EXMAC can be used in two different ways.    First, it can be used 
  128. as an interactive program.  You invoke the program in this way by 
  129. typing just "EXMAC myprog", where myprog.SYM is the name of the 
  130. symbols-file.  Then you can type in any number of macro-call 
  131. lines.  After each line, the program will display the expanded 
  132. program text it produces.  If the program does not think your 
  133. line is a macro call, it will simply echo the line back to you.  
  134. In this mode, you exit the program by typing control-Z at the 
  135. beginning of a line, then terminating the line with the ENTER 
  136. (RETURN on some computers) key.  On most IBM-compatible 
  137. computers, the control-Z code is also generated by the F6 key, 
  138. for convenience.  
  139.  
  140. The second way of using EXMAC is to feed a source-file to it.  It 
  141. will output the equivalent source-file with the macros expanded.  
  142. You may then, if you wish, rename the new file as the original 
  143. source file, and assemble the new file.  This method is useful if 
  144. you get an error on a macro expansion line, and you don't know 
  145. where the error came from.   To use EXMAC in this second way, you 
  146. simply redirect standard input and output: "EXMAC myprog  <in  
  147. >out".  With the redirection, EXMAC will take its input from the 
  148. file "in" instead of the keyboard; and it will send its output to 
  149. the file "out" instead of the screen.  (If you are not familiar 
  150. with redirection of standard input and output, you might want to 
  151. read about in Chapter 6, "Standard Input and Standard Output", of 
  152. the MS-DOS reference manual.) 
  153.                                                         13-4
  154. A86LIB Source File Library Tool
  155.  
  156. There is a tool, A86LIB, available only if you are registered, 
  157. that lets you build libraries of source files.  Here's how it 
  158. works:
  159.  
  160. First, you code and debug a source module that you want to go 
  161. into your library.  Then you feed the module to A86LIB.  A86LIB 
  162. enters all non-local labels and EQUates from your module into a 
  163. special dedicated file A86.LIB.
  164.  
  165. Next, you code a program that references a symbol from your 
  166. library module.  When A86 assembles your program, it sees that 
  167. the symbol is undefined.  A86 then looks in A86.LIB to see if 
  168. the symbol is catalogued there.  If it is, A86 assembles your 
  169. library source file.
  170.  
  171.  
  172. Environment Variable A86LIB
  173.  
  174. You can set an environment variable A86LIB to specify which 
  175. drives or subdirectories contain A86.LIB files.  The variable 
  176. consists of a sequence of path names separated by semicolons, 
  177. just like the PATH variable used by the operating system.  For 
  178. example, if you include in your AUTOEXEC.BAT file the line 
  179.  
  180.    SET A86LIB=C:\bin\lib;\tools\a86lib
  181.  
  182. then A86 will look for A86.LIB in the current directory, then it 
  183. will look for C:\bin\lib\A86.LIB, then \tools\a86lib\A86.LIB. 
  184. A86 will keep looking in all three library files until there are 
  185. no more undefined symbols, or there are no more source files to 
  186. assemble.
  187.  
  188. When A86 finds a symbol it needs in A86.LIB, it gets the name of 
  189. the library file containing the symbol.  The library file is 
  190. assumed to be in the same directory as its A86.LIB file, unless 
  191. a complete path name (starting with \ or a drive-specifier) was 
  192. fed to A86.LIB when A86.LIB was created.
  193.  
  194.  
  195. Forcing a Library Search
  196.  
  197. You may force A86 to assemble library files before moving on to 
  198. more of your program's source files.  You do this by placing a 
  199. pound sign # between file names in your invocation line.  For 
  200. example, suppose your program has two modules FIRST.8 and LAST.8.  
  201. FIRST.8 calls subroutines from your library; but you need the 
  202. library files assembled before LAST.8 is assembled.  (You might 
  203. want this because LAST.8 allocates memory space beyond the end of 
  204. your program, which would be the end of LAST.8 if it were truly 
  205. the last module.)  You accomplish this by the invocation line:
  206.  
  207.   A86 FIRST.8 # LAST.8
  208.  
  209. Note that there is never any need to force a library search at 
  210. the end of your program modules: A86 always makes a library 
  211. search there, if you have any undefined symbols.
  212.                                                           13-5
  213. Listings with A86
  214.  
  215. A86 does not produce a .LST file, or anything similar to it!  (We 
  216. now pause, to allow traditionalists to recover from their 
  217. swooning shock.)   OK, everybody back to consciousness?  Good.  
  218. Now let's all try to strip away our preconceptions, and look at 
  219. things with a fresh viewpoint.  
  220.  
  221. In particular, let's consider what we use a listing file for, and 
  222. see how A86 meets those needs.  I've been programming for 20 
  223. years; I have generated literally tons of listings.  
  224. Historically, here's what I have used listings for: 
  225.  
  226. 1. To find out what my error messages are.  In the early days of 
  227.    Intel, the text editor was so bad that it was actually faster 
  228.    to march across the building and physically print the list 
  229.    file, than it was to use an editor to find error messages!  
  230.    But even with a fast editor, what a pain it is to go into the 
  231.    list file, enduring its 120-column wide format on your 80-
  232.    column screen, copy down the errors on paper, then go back to 
  233.    the source file to find where the errors were.  Why doesn't 
  234.    the assembler just stick the messages directly into your 
  235.    source file, where you can view them and edit the source 
  236.    simultaneously?  That's what A86, and only A86, does.  
  237.  
  238. 2. To see what code was generated; those hexadecimal bytes at the 
  239.    left of the listing.  That was a real necessity, back in the 
  240.    days of hexadecimal debuggers.  There we were, furiously 
  241.    patching those hex object bytes.  We needed the listings to 
  242.    find our way around the program, while debugging.  Today, we 
  243.    have symbolic, disassembling debuggers, such as D86.  The 
  244.    power of today's debuggers means that you seldom need to look 
  245.    at hex object bytes.  If you do, the debugger can show them to 
  246.    you.  
  247.  
  248. 3. To get a symbol-table listing.  The necessity of this 
  249.    diminishes a great deal when you have a SYMBOLIC debugger; but 
  250.    I still like to have a listing from time to time.  So I have 
  251.    devised a separate program, XREF, that goes through another 
  252.    pass of the source file, and creates the world's finest cross-
  253.    reference listing for assemblers.  
  254.  
  255.    You may ask, "Why am I being forced to essentially re-assemble 
  256.    my code to get a symbol table, when other assemblers will give 
  257.    it to me in the original assembly?"  Don't be fooled.  Those 
  258.    other assemblers go through all your source files twice, or 
  259.    even three times.  They just do it behind your back, every 
  260.    time you want an assembly.  That's one reason why my assembler 
  261.    is so much faster than everyone else's.  
  262.                                                           13-6
  263. 4. To just look at the code.  I have often in the past needed to 
  264.    see that program, spread out on paper, just to get a handle on 
  265.    what the program is doing.  But I have needed this less and 
  266.    less lately.  Why?  For two reasons.  First, text editors have 
  267.    improved.  It's much, much easier than it was before to cruise 
  268.    through a file on the screen.  Second, my programs have 
  269.    adapted to the screen-viewing methodology.  Almost 
  270.    subconsciously, I have started making the conceptual "chunks" 
  271.    of my code fit into 1 or 2 24-line screens, rather than 1 or 2 
  272.    60-line pages.  This, of course, makes better, more modular 
  273.    programs.  (Spaghetti tends to untangle when you chop it up.)  
  274.    It's gotten to the point where I can develop (and have 
  275.    developed) a 5000-line application, fully debugged, without 
  276.    ever making a listing!  
  277.  
  278. 5. For archival purposes.  I still do this; you should never put 
  279.    100% trust in magnetic media.  But I've stripped away the 
  280.    reasons for having anything but the source code and the symbol 
  281.    table.  So I just copy the source files and the cross-
  282.    reference listing to the printer.  I haven't looked at the 
  283.    listings too much; so I haven't bothered with pagination 
  284.    control.  If you want to, you can insert form-feeds into your 
  285.    source; A86 will ignore them.  Or, you can write a simple 
  286.    listing-tool that recognizes the PAGE directive; A86 ignores 
  287.    that directive, also.  
  288.  
  289.  
  290.  
  291. Mimicking Tool: FAKE.EXE
  292.  
  293. As of this writing, Turbo C is aware only of the existence of 
  294. Microsoft's MASM for assembling source files it generates.  I 
  295. hope to persuade Borland to provide a switch to Turbo C that 
  296. causes it to invoke A86 directly.  Until that happens, I offer 
  297. the tool FAKE.EXE, that convinces Turbo C that A86 is really 
  298. MASM.
  299.  
  300. To use FAKE.EXE, it must be renamed MASM.EXE in your disk system.
  301. I would have named it MASM myself, except that
  302.  
  303. 1. Bill Gates would probably get mad at me if I did, and
  304.  
  305. 2. You need to decide what to do with your real MASM if you have 
  306.    it, before installing FAKE.  You could either place FAKE 
  307.    (named MASM.EXE) into the individual directories containing 
  308.    Turbo C programs, or you can rename MASM to something like 
  309.    MSM.EXE or REALMASM.EXE. 
  310.  
  311. Having renamed FAKE.EXE to MASM.EXE, you may now use the Turbo 
  312. C's switch, -B, that allows you to place A86 statements into your 
  313. C program.  You don't need to worry about the gory details of 
  314. what FAKE does. 
  315.                                                           13-7
  316. If you like gory details, here they are: FAKE filters the command 
  317. line handed to it, replacing switches: 
  318.  
  319.    /D becomes =
  320.    /mx becomes +c
  321.    /E becomes +f
  322.  
  323. FAKE also eliminates the semicolon, appends .ASM to the source 
  324. file name, and turns on the O and S switches.  It then feeds the 
  325. resulting filtered command line to A86 for assembly.
  326.  
  327. FAKE is really a COM file (MS-DOS doesn't seem to care if a COM 
  328. file is named EXE).  I've named it EXE because Turbo C looks 
  329. specifically for MASM.EXE and will ignore MASM.COM.
  330.  
  331.  
  332.